import networkx as nx
import matplotlib.pyplot as plt



def draw_graph(graph):

    # extract nodes from graph
    nodes = set([n1 for n1, n2 in graph] + [n2 for n1, n2 in graph])

    # create networkx graph
    G=nx.Graph()

    # add nodes
    for node in nodes:
        G.add_node(node)

    # add edges  
    for edge in graph:
        G.add_edge(edge[0], edge[1])

    # draw graph
    nx.draw(G)

    # show graph
    plt.show()

# draw example

if __name__ == '__main__':
#    graph = [(20, 21),(21, 22),(22, 23), (23, 24),(24, 25), (25, 20)]
    graph = []
    seqList = []
    with open ("seqSet.txt", 'r') as seqfile:
        seqList = seqfile.readlines()

    with open ("datasetGraph.txt", 'r') as f:
        s =  f.readlines()
        i = 0
        for line in s:
            i+=1
            if i > 5:
                break
            line = line.split(',')
            line[1] = seqList.index(line[1])
            line = ""+str(line[0][:4])+","+str(line[1])
            string = "("+line+")"
            print (string)
            graph.append(s)
    print(graph)
    draw_graph(graph)

